﻿@model PH.Model.Achievements.ArchiveModel
<style>
    .sel { display:inline-block; width:70%; border:dashed 1px #ccc; line-height:30px; padding:5px 10px }
    .sel span { }
    .sel span input { width:auto; }
</style>
<div class="GeneralEdit" id="fmArchive">
    <ul>
        <li>
            <label for="txtTitle">标题：</label>
            <input type="text" class="k-textbox" id="txtTitle" name="title" value="@Model.Title" required validationMessage="请输入标题" />
            <span class="k-invalid-msg" data-for="title"></span>
        </li>
        <li>
            <label for="txtDescription">描述：</label>
            <textarea class="k-textbox" id="txtDescription" rows="5" style="width:300px">@Model.Description</textarea>
        </li>
        <li>
            <label for="txtStartDate">开始时间：</label>
            <input type="date" id="txtStartDate" name="startDate" class="date" required />
            <span class="k-invalid-msg" data-for="startDate"></span>
        </li>
        <li>
            <label for="txtEndDate">截止时间：</label>
            <input type="date" id="txtEndDate" name="endDate" class="date" required />
            <span class="k-invalid-msg" data-for="endDate"></span>
        </li>
        <li class="editButtons">
            <button id="btnSaveArchive" class="k-button"><span class="k-icon k-i-tick"></span><span>确认提交</span></button>
            &nbsp;&nbsp;
            <button class="k-button" onclick="CancelGeneralEdit();"><span class="k-icon k-i-cancel"></span><span>&nbsp;返&nbsp;回</span></button>
        </li>
    </ul>
</div>

<script class="init">
    $(".date").kendoDatePicker({
        format: "yyyy-MM-dd"
    });
    if ("@(Model.Guid!=Guid.Empty)" == "True") {
        $("#txtStartDate").data("kendoDatePicker").value(kendo.parseDate('@string.Format("{0:yyyy-MM-dd}",Model.BeginTime)'));
        $("#txtEndDate").data("kendoDatePicker").value(kendo.parseDate('@string.Format("{0:yyyy-MM-dd}",Model.EndTime)'));
    }
    
    function SelectAll(obj) {
        $(".sel input[type='checkbox']").prop("checked", $(obj).is(":checked"));
    }
</script>

<script class="save_archive">
    $(function () {
        var validator = $("#fmArchive").kendoValidator().data("kendoValidator");
        $("#btnSaveArchive").click(function (e) {
            if (validator.validate()) {
                var values = {
                    guid: "@Model.Guid",
                    title: $("#txtTitle").val(),
                    description: $("#txtDescription").val(),
                    sDate: kendo.toString($("#txtStartDate").data("kendoDatePicker").value(), "yyyy-MM-dd"),
                    eDate: kendo.toString($("#txtEndDate").data("kendoDatePicker").value(), "yyyy-MM-dd")
                };

                Whale.Remote.Operation({
                    url: "/Achievements/Archive/SaveArchive",
                    parameters: values,
                    success: function (result) {
                        wndGeneralEdit.close();
                        if ($("#grid_archives").length > 0)
                            $("#grid_archives").data("kendoGrid").dataSource.read();
                    },
                    error: function (msg) {
                        wndGeneralInformation.content(msg).open();
                    }
                });
            }
            return false;
        });
    });
</script>
